<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>封装字典</title>
    1. 通过key:value 一一对应的关系
    <br>
    2. 字典中的key不可重复，value可重复
    <br>
    3. 字典中的key是无序的
</head>
<body>
    <script>
        class Dictionary {
            constructor() {
                this.items = {}
            }
            set(key, value) {
                this.items[key] = value
            }
            has(key) {
                return this.items.hasOwnProperty(key)
            }
            remove(key) {
                if (this.has(key)) return false
                delete this.items[key]
                return true
            }
            get(key) {
                return this.has(key) ? this.items[key] : undefined
            }
            keys() {
                return Object.keys(this.items)
            }
            values() {
                return Object.values(this.items)
            }
            size() {
                return this.keys().length
            }
            clear() {
                this.items = {}
            }
        }
    </script>
</body>
</html>